package org.oschina.api.favorite.type.dao;

import java.util.List;

import org.oschina.api.BaseDAO;
import org.oschina.api.favorite.type.model.FavoriteType;
import org.oschina.api.favorite.type.vo.FavoriteTypeVo;
import org.springframework.stereotype.Repository;

@Repository
public class FavoriteTypeDAO extends BaseDAO {

	private final String findVo[]={"id","name","url"};
	
	/**
	 * 返回
	 * @return
	 */
	public List<FavoriteTypeVo> findVo()
	{
		return getQueryHelper().query_cache(findVo, null, null, null, FavoriteTypeVo.class, -1, -1);
	}
	
	/**
	 * 根据ID返回
	 * @param id
	 * @return
	 */
	public FavoriteTypeVo findVoById(int id)
	{
		return (FavoriteTypeVo) getQueryHelper().queryForObject_cache(findVo, new String[]{"id=?"}, new Object[]{id}, FavoriteTypeVo.class);
	}
	
	/**
	 * 更新
	 * @param favoriteType
	 * @return
	 */
	public int update(FavoriteType favoriteType)
	{
		return (int) getQueryHelper().update_cache(new String[]{"name=?","url=?"}, new String[]{"id=?"}, new Object[]{favoriteType.getName(),favoriteType.getUrl(),favoriteType.getId()}, FavoriteTypeVo.class);
	}
}